﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;

//namespace PinLayoutMVC.Models.Helper
//{
//    public static class Transaction
//    {



//        public static SurveyTemplateModel insertExecute(SurveyModel surveyModel, SurveyTemplate surveyTemplate, SurveyHeaderTag surveyHeaderTemplate)
//        {
//            SQL2005_819929_smrEntities dbEntity = new SQL2005_819929_smrEntities();

//            Survey survey = new Survey();
//            survey.SurveyTemplateID = surveyModel.SurveyTemplateID;
//            survey.StartDate = surveyModel.StartDate;
//            survey.EndDate = surveyModel.EndDate;
//            survey.Name = surveyModel.SurveyName;
//            survey.Description = surveyModel.SurveyDescription;
//            survey.Status = surveyModel.GetState();



//            SurveyTemplate surveytemplate = new SurveyTemplate();
//            surveytemplate.SurveyTemplateID = surveyTemplate.SurveyTemplateID;

//            surveytemplate.StartDate = surveyTemplate.StartDate;
//            surveytemplate.EndDate = surveyTemplate.EndDate;
//            surveytemplate.Description =surveyTemplate.Description;
//            surveytemplate.Name = surveyTemplate.Name;
//            surveytemplate.SurveyTemplateID = surveyTemplate.SurveyTemplateID;

//            SurveyHeaderTag surveyheadertemplate = new SurveyHeaderTag();
//            surveyheadertemplate.SurveyID = survey.SurveyID;
//            surveyheadertemplate.ID = surveyHeaderTemplate.ID;
//            surveyheadertemplate.JsScript = surveyHeaderTemplate.JsScript;
//            surveyheadertemplate.MetaData = surveyHeaderTemplate.MetaData;
//            surveyheadertemplate.CssScript = surveyHeaderTemplate.CssScript;
//            surveyheadertemplate.Title = surveyHeaderTemplate.Title;


//            survey.SurveyHeaderTags.Add(surveyheadertemplate);
//            surveytemplate.SurveyHeaderTags.Add(surveyheadertemplate);
//            surveytemplate.Surveys.Add(survey);

//            dbEntity.AddToSurveyTemplates(surveytemplate);

//            dbEntity.SaveChanges();



//            SurveyTemplateModel returnValue = new SurveyTemplateModel();
//            returnValue.CssScript = surveyheadertemplate.CssScript;
//            returnValue.HeaderID = surveyheadertemplate.ID;
//            returnValue.CssScript = surveyheadertemplate.JsScript;
//            returnValue.MetaData = surveyheadertemplate.MetaData;
            
//            returnValue.Name = surveytemplate.Name;
//            returnValue.StartDate = surveytemplate.StartDate;
//            returnValue.TemplateID = surveytemplate.SurveyTemplateID;
//            returnValue.SurveyID = survey.SurveyID;
//            returnValue.Title = surveyHeaderTemplate.Title;

//            return returnValue;
//        }

//        public static int updateExecute(SurveyTemplateModel stm)
//        {
//            SQL2005_819929_smrEntities dbEntity = new SQL2005_819929_smrEntities();

//            Survey surveyEdit = (from p in dbEntity.Surveys where p.SurveyID == stm.SurveyID && p.SurveyTemplateID == stm.TemplateID select p).First();
//            SurveyTemplate surveyTemplateEdit = (from p in dbEntity.SurveyTemplates where p.SurveyTemplateID == stm.TemplateID select p).First();
//            SurveyHeaderTag SurveyHeaderTagEdit = (from p in dbEntity.SurveyHeaderTags where p.SurveyID == stm.SurveyID && p.SurveyTemplateID == stm.TemplateID && p.ID == stm.HeaderID select p).First();

//            surveyEdit.SurveyTemplateID = stm.TemplateID;
//            surveyEdit.StartDate = stm.StartDate;
//            surveyEdit.EndDate = stm.EndDate;
//            surveyEdit.Name = stm.Name;
//            surveyEdit.Description = stm.Description;
//            surveyEdit.Status = stm.survey.GetState();

//            surveyTemplateEdit.StartDate = stm.StartDate;
//            surveyTemplateEdit.EndDate = stm.EndDate;
//            surveyTemplateEdit.Description = stm.Description;
//            surveyTemplateEdit.Name = stm.Name;


//            SurveyHeaderTagEdit.ID = stm.HeaderID;
//            SurveyHeaderTagEdit.JsScript = stm.JsScript;
//            SurveyHeaderTagEdit.MetaData = stm.MetaData;
//            SurveyHeaderTagEdit.CssScript = stm.CssScript;

//            dbEntity.SaveChanges(); 



//            return 1;
//        }

//        public static int deleteExecute(SurveyTemplateModel stm)
//        {
//            SQL2005_819929_smrEntities dbEntity = new SQL2005_819929_smrEntities();

//            Survey surveyDelete = (from p in dbEntity.Surveys where p.SurveyID == stm.SurveyID && p.SurveyTemplateID == stm.TemplateID select p).First();
//            SurveyTemplate surveyTemplateDelete = (from p in dbEntity.SurveyTemplates where p.SurveyTemplateID == stm.TemplateID select p).First();
//            SurveyHeaderTag SurveyHeaderDelete = (from p in dbEntity.SurveyHeaderTags where p.SurveyID == stm.SurveyID && p.SurveyTemplateID == stm.TemplateID && p.ID == stm.HeaderID select p).First();

//            dbEntity.SurveyHeaderTags.DeleteObject(SurveyHeaderDelete);
//            dbEntity.Surveys.DeleteObject(surveyDelete);

//            dbEntity.SurveyTemplates.DeleteObject(surveyTemplateDelete);

//            dbEntity.SaveChanges();

//            return 1;
//        }

//    }
//}